#include <algorithm>
#include <cstdio>
const int N = 53;
int n, m, t, f[N][N][2505], q[N];
char str[N];
int chk[N][N][N];
int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#endif
#ifndef LOCAL
  freopen("painter.in", "r", stdin);
  freopen("painter.out", "w", stdout);
#endif
#endif

  scanf("%d%d%d", &n, &m, &t);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", str + 1);
    for (int j = 1; j <= m; ++j) {
      int vis = 0;
      for (int k = j; k <= m; ++k) {
        if (str[j] == str[k]) ++vis;
        chk[i][j][k] = std::max(vis, k - j + 1 - vis);
      }
    }
  }
  for (int k = 1; k <= t; ++k) {
    for (int i = 1; i <= n; ++i) {
      f[i][0][k] = f[i - 1][m][k];
      int l = 0, r = 0;
      for (int j = 1; j <= m; ++j) {
        if (j > 0) f[i][j][k] = std::max(f[i][j][k], f[i][j - 1][k]);
        f[i][j][k] = std::max(f[i][j][k], f[i][q[l]][k - 1] + chk[i][q[l] + 1][j]);
        while (l < r &&
               f[i][j][k - 1] + chk[i][j + 1][j] >= f[i][q[r]][k - 1] + chk[i][q[r]][j])
          --r;
        q[++r] = j;
      }
    }
  }
  printf("%d", f[n][m][t]);
  return 0;
}